#include "Bank_t.h"
#include "AccountImpl.h"
#include <typeinfo>

Bank_t Bank_t::sngBank(2011);

void Bank_t::Attach(AccountImpl* acc) {
	m_observers.push_back(acc);
} 

void Bank_t::Detach(AccountImpl* acc) {
	m_observers.remove(acc);
} 

void Bank_t::Notify3YearAccounts() {
	for (list<AccountImpl*>::iterator it = m_observers.begin(); it != m_observers.end(); ++it) {
		if ((*it)->getPeriod() == 3)
			(*it)->Update(this, "Please come to meet the clerk");
	}
}

void Bank_t::NotifyFamilyAccounts() {
	for (list<AccountImpl*>::iterator it = m_observers.begin(); it != m_observers.end(); ++it) {
		if ((*it)->getAccountType() == Family_e)
			(*it)->Update(this, "You've been given 500 shekels");
	}
}

void Bank_t::NotifyStockAccounts() {
	for (list<AccountImpl*>::iterator it = m_observers.begin(); it != m_observers.end(); ++it) {
		if ((*it)->getAccountType() == Stock_e && (*it)->getPeriod() == 10 && m_curYear - (*it)->getDate() <= 5)
			(*it)->Update(this, "The bank decided to invest in stock exchange");
	}
}
